//地图公交
import React, { Component } from 'react';
import {
    View,
    Text,
    ListView,
    TouchableOpacity,
} from 'react-native';


import Icon from 'react-native-vector-icons/Ionicons';
import { mapbusStyle as styles } from '../../../styles';

var Dimensions = require('Dimensions');
var width = Dimensions.get('window').width;
var height = Dimensions.get('window').height;
import Bus_list from './busnum';

const ds = new ListView.DataSource({ rowHasChanged: (r1, r2) => r1 !== r2 });
export default class Mapbus extends Component {
    constructor(props) {
        super(props);
        this.state = {
            Lines: [],
            isCrossCity:false
        };
    }

    renderRow(rowData) {
        let walkWay = 0;
        let stationNum = 0;
        let entrance = "";
        let steps = [];
        if(this.state.isCrossCity){
            return (
                <TouchableOpacity style={styles.busevery} activeOpacity={1}
                onPress={() => { this.props.navigation.navigate('Busin',{Lines:this.state.Lines,latLng:this.props.latLng}) }}>
                    <View style={styles.busone}>
                        <Text style={styles.bustime}>{(rowData.duration/60).toFixed(0)}分钟</Text>
                        <Text style={styles.busrange}>{(rowData.distance/1000).toFixed(1)}公里</Text>
                    </View>
    
                    <Bus_list steps={rowData.transitSteps}/>
    
                    <View style={styles.busthree}>
                        {rowData.transitSteps.map((item,key)=>{
                            return(<Text key={key} style={styles.busplace}>{item.departureStation}</Text>)
                        })}
                    </View>
    
                    <Icon
                        name={'ios-arrow-forward'}
                        size={20}
                        color={'#3d9ccc'} style={styles.busarr} />
                </TouchableOpacity>
    
            )
        }else{
            for(let i =0;i<rowData.transitSteps.length;i++){
                if(rowData.transitSteps[i].stepType=="WAKLING"||rowData.transitSteps[i].stepType=="ESTEP_WALK"){
                    walkWay += rowData.transitSteps[i].distance
                }else{
                    if(entrance=="")entrance = rowData.transitSteps[i].entrance
                    stationNum += rowData.transitSteps[i].vehiclePassStationNum
                    steps.push(rowData.transitSteps[i]);
                }
            }
            return (
                <TouchableOpacity style={styles.busevery} activeOpacity={1}
                onPress={() => { this.props.navigation.navigate('Busin',{Lines:this.state.Lines,latLng:this.props.latLng}) }}>
                    <View style={styles.busone}>
                        <Text style={styles.bustime}>{(rowData.duration/60).toFixed(0)}分钟</Text>
                        <Text style={styles.busrange}>步行{walkWay}米</Text>
                    </View>
    
                    <Bus_list steps={steps}/>
    
                    <View style={styles.busthree}>
                        <Text style={styles.busplace}>{entrance}上车</Text>
                        <Text style={styles.busplace}>共{stationNum}站</Text>
                    </View>
    
                    <Icon
                        name={'ios-arrow-forward'}
                        size={20}
                        color={'#3d9ccc'} style={styles.busarr} />
                </TouchableOpacity>
            )
        }

    }
}

